
#ifndef _Container_H_
#define _Container_H_

#include <container.h>
#include <Critsec.h>

class _TObjectEnumerator : public IObjectEnumerator
{
public:
    CARAPI_(PInterface) Probe(
        /* [in] */ REIID riid);

    CARAPI_(UInt32) AddRef();

    CARAPI_(UInt32) Release();

    CARAPI Aggregate(
        /* [in] */ AggregateType type,
        /* [in] */ PInterface pObj);

    CARAPI GetDomain(
        /* [out] */ PInterface *ppObj);

    CARAPI Current(
        /* [out] */ PInterface *ppObj);

    CARAPI MoveNext(
        /* [out] */ Boolean *pSucceeded);

    CARAPI Reset();

    _TObjectEnumerator(
        ObjectNode *pHeader,
        CCriticalSection *pLock,
        Int32 *pState);

    virtual ~_TObjectEnumerator() {};

private:
    Interlocked          m_cRef;

    ObjectNode           *m_pHeader;
    ObjectNode           *m_pCurrent;
    CCriticalSection      *m_pLock;
    Int32                *m_pState;
    Int32                m_nOrigState;
};

class CContainer : public SimpleContainer
{
public:
    CARAPI Add(IInterface *pObject);

    CARAPI Remove(IInterface *pObject);

    CARAPI GetEnumerator(IObjectEnumerator **ppEnumerator);

    CARAPI GetCount(Int32 *pCount);

    CARAPI Dispose();

    CContainer() : m_nCount(0), m_nState(0)
    {
        m_lock.Initialize();
    };

    ~CContainer()
    {
        this->Dispose();
    };

private:
    int  m_nCount;
    int  m_nState;
    CCriticalSection m_lock;
};

#endif

